<template>
	<view class="container">
		<view class="intro">
			<image :src="logoUrl"></image>
			<view class="tips">
				一杯奶茶，一口汉堡
				<br>
				在麦乐士遇见两种美好
			</view>
		</view>
		<view class="bottom">
			<!-- #ifdef H5 -->
				<button type="primary" size="default" class="login-btn" @tap="login">
					登录
				</button>
			<!-- #endif -->
			<!-- #ifdef MP-WEIXIN -->
				<button type="primary" size="default" class="login-btn" lang="zh_CN" @tap="getUserInfo">
					<image src="/static/images/mine/wechat.png"></image>
					微信一键登录
				</button>
			<!-- #endif -->
			<view class="d-flex flex-column justify-content-evenly align-items-center text-center" style="height: 30vh;">
				<view class="w-100 font-size-base text-color-assist">新用户登录即加入会员，享会员权益</view>
				<view class="w-100 row d-flex just-content-around align-items-center font-size-sm text-color-assist">
					<view class="grid">
						<image src="/static/images/mine/rhyl.png"></image>
						<view>入会有礼</view>
					</view>
					<view class="grid">
						<image src="/static/images/mine/jfdh.png"></image>
						<view>积分兑换</view>
					</view>
					<view class="grid">
						<image src="/static/images/mine/sjtq.png"></image>
						<view>升级特权</view>
					</view>
					<view class="grid">
						<image src="/static/images/mine/srtq.png"></image>
						<view>生日特权</view>
					</view>
				</view>
				<!-- <view class="font-size-base text-color-primary">会员权益说明</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import {mapMutations} from 'vuex'
	import Request from '@/js_sdk/luch-request/luch-request/index.js' // 下载的插件
	// const http = new Request();
	export default {
		data() {
			return {
				openid:'',
				logoUrl:'',
			}
		},
		onShow() {
			this.$http.get('sys/config', {params: {}}).then(res => {
				this.logoUrl = res.data.data.logo
				
			}).catch(err => {
			
			})
		},
		methods: {
			...mapMutations(['SET_MEMBER']),
			async getUserInfo() {
				uni.login({
					success:(e)=> {
						this.$http.get('wx/login', {params: {code:e.code}}).then(res => {
							console.log(res)
							let openid = res.data.data.openid
							if(!openid){
								return uni.showModal({
									content:'授权失败'
								})
							}else{
								this.openid = openid
							}
						}).catch(err => {
						
						})
						// console.log(e)
					}
				})
				uni.getUserProfile({
					'desc':'获取用户信息',
					success:(e)  =>{
					    // console.log(e.userInfo);
						// {avatarUrl: avatar, city, country, gender, nickName: nickname, province} = e.userInfo
						// const member = Object.assign(Member, {avatar, city, country, gender, nickname, province})
						e.userInfo.openid = this.openid
						// console.log(e.userInfo)
						this.$http.post('/wx/checkLogin', e.userInfo).then(res => {
							let token = res.data.data.token
							uni.setStorageSync('token',token)
							this.$http.setConfig((config) => { /* config 为默认全局配置*/
							    config.header = {
							        Authorization: 'Bearer '+ token,
							    }
							    return config
							})
							this.SET_MEMBER(res.data.data)
							uni.navigateBack()
						}).catch(err => {
						
						})
					},
					fail:function(e){
						uni.navigateBack()
						return
					}
				})
			},
			login() {
				this.SET_MEMBER(Member)
				uni.navigateBack()
			}
		},
	}
</script>

<style lang="scss" scoped>
	.intro {
		width: 100%;
		height: 60vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-evenly;
		font-size: $font-size-base;
		color: $text-color-assist;
		
		image {
			width: 165rpx;
			height: 165rpx;
		}
		
		.tips {
			line-height: 72rpx;
			text-align: center;
		}
	}
	
	.bottom {
		height: 40vh;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		padding: 0 40rpx;
		
		.login-btn {
			width: 100%;
			border-radius: 50rem !important;
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 10rpx 0;
			
			image {
				width: 36rpx;
				height: 30rpx;
				margin-right: 10rpx;
			}
		}
		
		.row {
			.grid {
				width: 20%;
				image {
					width: 60rpx;
					height: 60rpx;
					margin-bottom: 10rpx;
				}
			}
		}
	}
</style>
